#include "StdAfx.h"
#include "FileUtil.h"


FileUtil::FileUtil(void)
{
}


FileUtil::~FileUtil(void)
{
}

string FileUtil::modulePath(void)
{
	char path_buffer[_MAX_PATH];
	char drive[_MAX_DRIVE];
	char dir[_MAX_DIR];
	char fname[_MAX_FNAME];
	char ext[_MAX_EXT];
	GetModuleFileName(NULL, path_buffer, _MAX_PATH);
	_splitpath_s(path_buffer, drive, dir, fname, ext);

	string strDir;
	strDir += drive;
	strDir += dir;
	
	//AfxMessageBox(strDir);

	return strDir;
}

void FileUtil::createPath(const char* path)
{
	CFileFind ff;
	if (!ff.FindFile(path))
	{
		CreateDirectory(path, NULL);
	}
}

bool FileUtil::getSubFileNameList(CArray<CString>& arr,const char* direction)
{
	CString path=direction;
	path.Append("*.*");

	WIN32_FIND_DATA FindFileData;
	HANDLE hFind=::FindFirstFile(path,&FindFileData);
	if(INVALID_HANDLE_VALUE == hFind)   
	{
		FindClose(hFind);
		return false;
	}

	do 
	{
		if(FindFileData.cFileName[0]!='.')
		{
			arr.Add(FindFileData.cFileName);
		}

	} while (FindNextFile(hFind,&FindFileData));

	FindClose(hFind);

	return true;
}